package net.alcuria.ball;

import java.util.ArrayList;

public class Director {

	ArrayList<Particle> spriteList; 	
	private final int maxSprites = 10; // maximum number of sprites a director can handle
	
	public Director(){
		spriteList = new ArrayList<Particle>();
	}
	
	public void add(Particle p){
		if (spriteList.size() < maxSprites){
			p.particle.looping = false;
			spriteList.add(p);
		}
	}
	
	public void remove(int index){
		if(index < spriteList.size()){
			spriteList.remove(index);
		}
	}
	
	public void update(){
		
		// iterate through and update every element in the list
		for(int i = 0; i < spriteList.size(); i++){
			spriteList.get(i).update(0);
			
			// remove any particles that have looped once
			if(spriteList.get(i).particle.frameIndex >= 10){
				spriteList.remove(i);
			}
		}
	}
	
	public int getSize(){
		return spriteList.size();
	}
}
